using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace gears
{
    class Stage
    {

        private Mechanism mechanism;
        private Texture2D killer_texture;
        private Texture2D stage_door_texture;
        private Texture2D pulley_texture;
        private Texture2D hand_lifitng_texture;
        private Texture2D pressure_lever_texture;
        private Texture2D lever_texture;
        private Texture2D hydrolic_lifter;
        private Texture2D tube_texture;
        private Texture2D tube_door_texture;
        private Vector2 stage_door_position;
    
        private List<Animation> ropes_animation = new List<Animation>();
        private List<Animation> hand_lifting_ropes_animation = new List<Animation>();
        private Animation sand_animation;
        private Animation fire_torch_animation;

        private List<Vector2> killers_position = new List<Vector2>();
        private List<Vector2> ropes_position = new List<Vector2>();
        private List<Vector2> ropes_scales = new List<Vector2>();
        private List<Vector2> pulley_positions = new List<Vector2>();
        private List<Vector2> hand_lifiting_ropes_position = new List<Vector2>();
        private List<Vector2> hand_lifing_ropes_scale = new List<Vector2>();
        private List<Vector2> fire_torch_position=new List<Vector2>();

        private Vector2 hydrolic_lifter_position;
        private Vector2 lever_position;
        private Vector2 pressure_lever_position;
        private Vector2 hand_lifting_position;
        private Vector2 tube_position;
        private Vector2 tube_door_position;

        private int tube_position_offset = 0;

        private List<float> pulley_rotations = new List<float>();
        private List<float> ropes_rotate = new List<float>();
        private List<float> hand_lifting_ropes_rotation = new List<float>();
        private float hand_lifitng_rotation = 0;

        private string killer_type = "";
        private float stage_door_angle =0;
        private float tube_angle = 0;
        private int door_texture_current_height = 0;
        private int door_texture_current_width = 0;
        private int tube_door_height = 0;
        
        private int stage_number = 0;
        private Vector2 player_position=new Vector2(0,0);

        private bool stage_solved = false;
        private bool stage_incorrect_solved = false;
        private bool stage_reset = false;

        public Stage(int _stage_number,SpriteBatch sb)
        {
            stage_number = _stage_number;

            fire_torch_animation = new Animation(ContentLoader.LoadTexture("stage_elements/fire_torch"), 5, 1, 10);

            if (_stage_number == 0)
            {
                Mechanism mech = new Mechanism(new Vector2(400f, 437f), sb, ContentLoader.LoadTexture("start_machine_button"), ContentLoader.LoadTexture("mechanism_box"), ContentLoader.LoadTexture("mechanism_background"), ContentLoader.LoadTexture("objective4"));
                GearWheel gw = new GearWheel(new Vector2(300, 400), 40, 0.0f, ContentLoader.LoadTexture("gearWheel400"), ContentLoader.LoadTexture("tooth2"), ContentLoader.LoadTexture("smallNumbers/num0"));
                Axis ax = new Axis(new Vector2(500, 200), ContentLoader.LoadTexture("axis1"));
                mech.AddWheel(new GearWheel(new Vector2(300, 400), 40, 0.0f, ContentLoader.LoadTexture("gearWheel400"), ContentLoader.LoadTexture("tooth2"), ContentLoader.LoadTexture("smallNumbers/num1")));
                mech.AddWheel(new GearWheel(new Vector2(300, 400), 20, 0.0f, ContentLoader.LoadTexture("gearWheel400"), ContentLoader.LoadTexture("tooth2"), ContentLoader.LoadTexture("smallNumbers/num2")));
                mech.AddWheel(new GearWheel(new Vector2(300, 400), 10, 0.0f, ContentLoader.LoadTexture("gearWheel400"), ContentLoader.LoadTexture("tooth2"), ContentLoader.LoadTexture("smallNumbers/num4")));
                mech.AddWheel(new GearWheel(new Vector2(300, 400), 7, 0.0f, ContentLoader.LoadTexture("gearWheel400"), ContentLoader.LoadTexture("tooth2"), ContentLoader.LoadTexture("smallNumbers/num6")));
                mech.AddWheel(new GearWheel(new Vector2(300, 400), 6, 0.0f, ContentLoader.LoadTexture("gearWheel400"), ContentLoader.LoadTexture("tooth2"), ContentLoader.LoadTexture("smallNumbers/num7")));
                mech.AddWheel(gw);
                mech.AddAxis(ax);
                mech.AddAxis(new Axis(new Vector2(230, 200), ContentLoader.LoadTexture("axis1")));
                //gw.HandDrived = true;
                gw.IsFixed = true; // the player cant able to change this wheel (need only if not hand drived)
                gw.GearWheelPostion = ax.Position;
                gw.Axis = ax;
                ax.Driver = true;
                ax.RotateSpeed = 0.02f;
                ax.Gear = gw;
                mech.Input = 4; // how many times (need only if not hand drived)
                mech.ExpectedOutput = 4;
                mech.OrganizeSelector(); // sort the unselected wheels
                mechanism = mech;
                stage_door_position = new Vector2(700, 360);
               
                stage_door_texture = ContentLoader.LoadTexture("stage_elements/stage2_door");
                door_texture_current_height = stage_door_texture.Height;
                door_texture_current_width = stage_door_texture.Width;

                tube_texture = ContentLoader.LoadTexture("stage_elements/tube");
                tube_position = new Vector2(0,360);
               

                tube_door_texture = ContentLoader.LoadTexture("stage_elements/tube_door");
                tube_door_position = new Vector2(30, 462);
                tube_door_height = tube_door_texture.Height;

                sand_animation = new Animation(ContentLoader.LoadTexture("stage_elements/sand_texture"), 2, 1, 10);
                killers_position.Add(new Vector2(-790,360));

                killer_type = "sand";

                hydrolic_lifter = ContentLoader.LoadTexture("stage_elements/hydraulic_lifter");
                hydrolic_lifter_position = new Vector2(500,365);
                pressure_lever_texture = ContentLoader.LoadTexture("stage_elements/pressure_lever");
                pressure_lever_position = new Vector2(470, 455);
                lever_texture = ContentLoader.LoadTexture("stage_elements/lever");
                lever_position = new Vector2(595,450);

                pulley_texture = ContentLoader.LoadTexture("stage_elements/pulley");

                ropes_animation.Add(new Animation(ContentLoader.LoadTexture("stage_elements/rope"), 2, 1, 10));
                ropes_animation[ropes_animation.Count - 1].Animating();
                ropes_scales.Add(new Vector2(100, 10));
                ropes_rotate.Add(0);
                ropes_position.Add(new Vector2(300, 370));
                ropes_animation.Add(new Animation(ContentLoader.LoadTexture("stage_elements/rope"), 2, 1, 10));
                ropes_animation[ropes_animation.Count - 1].Animating();
                ropes_scales.Add(new Vector2(100, 10));
                ropes_rotate.Add(0);
                ropes_position.Add(new Vector2(200, 370));
                
                ropes_animation.Add(new Animation(ContentLoader.LoadTexture("stage_elements/rope"), 2, 1, 10));
                ropes_animation[ropes_animation.Count - 1].Animating();
                ropes_scales.Add(new Vector2(80, 10));
                ropes_rotate.Add(0);
                ropes_position.Add(new Vector2(140, 370));

                ropes_animation.Add(new Animation(ContentLoader.LoadTexture("stage_elements/rope"), 2, 1, 10));
                ropes_animation[ropes_animation.Count - 1].Animating();
                ropes_scales.Add(new Vector2(140, 10));
                ropes_rotate.Add(-0.65f);
                ropes_position.Add(new Vector2(30, 455));

                ropes_animation.Add(new Animation(ContentLoader.LoadTexture("stage_elements/rope"), 2, 1, 10));
                ropes_animation[ropes_animation.Count - 1].Animating();
                ropes_scales.Add(new Vector2(60, 10));
                ropes_rotate.Add(-55);
                ropes_position.Add(new Vector2(400, 370));

                pulley_positions.Add(new Vector2(380, 390));
                pulley_rotations.Add(0);

                pulley_positions.Add(new Vector2(140, 390));
                pulley_rotations.Add(0);

                fire_torch_position.Add(new Vector2(80, 370));
                fire_torch_position.Add(new Vector2(180, 370));
                fire_torch_position.Add(new Vector2(280, 370));
                fire_torch_position.Add(new Vector2(400, 370));
                fire_torch_position.Add(new Vector2(480, 370));
                fire_torch_position.Add(new Vector2(640, 370));

              

            }
            else if (_stage_number == 1)
            {

                Mechanism mech2 = new Mechanism(new Vector2(350f, 197f), sb, ContentLoader.LoadTexture("start_machine_button"), ContentLoader.LoadTexture("mechanism_box"), ContentLoader.LoadTexture("mechanism_background"), ContentLoader.LoadTexture("objective2"));
                GearWheel gw2 = new GearWheel(new Vector2(200, 400), 40, 0.0f, ContentLoader.LoadTexture("gearWheel400hand"), ContentLoader.LoadTexture("tooth2"), ContentLoader.LoadTexture("smallNumbers/num1"));
                GearWheel gw3 = new GearWheel(new Vector2(210, 400), 10, 0.0f, ContentLoader.LoadTexture("gearWheel400"), ContentLoader.LoadTexture("tooth2"), ContentLoader.LoadTexture("smallNumbers/num1"));

                Axis ax2 = new Axis(new Vector2(415, 210), ContentLoader.LoadTexture("axis1"));
                Axis ax3 = new Axis(new Vector2(210, 200), ContentLoader.LoadTexture("axis1"));

                mech2.AddWheel(gw3);
                mech2.AddWheel(gw2);

                mech2.AddAxis(ax2);
                mech2.AddAxis(ax3);

                gw2.HandDrived = true;
                gw2.GearWheelPostion = ax2.Position;
                gw2.Axis = ax2;
                gw2.SetTeethToAngle(-1 * (float)(Math.PI / 2));

                gw3.GearWheelPostion = ax3.Position;
                gw3.Axis = ax3;
                gw3.IsFixed = true;
                ax2.Gear = gw2;
                ax3.Gear = gw3;
                mech2.Active = true;
                mech2.ExpectedOutput = 8;
                mech2.OrganizeSelector();
                mechanism=mech2;

                stage_door_texture = ContentLoader.LoadTexture("stage_elements/stage2_door");
                stage_door_position = new Vector2(700, 120);

                door_texture_current_height = stage_door_texture.Height;
                door_texture_current_width = stage_door_texture.Width;

                killer_texture = ContentLoader.LoadTexture("stage_elements/sand_texture");

                killers_position.Add(new Vector2(0,120));
                killer_texture = ContentLoader.LoadTexture("stage_elements/stage2_door");
                killer_type = "box";

                pulley_texture = ContentLoader.LoadTexture("stage_elements/pulley");

                //right
                ropes_animation.Add(new Animation(ContentLoader.LoadTexture("stage_elements/rope"), 2, 1, 10));
                ropes_animation[ropes_animation.Count - 1].Animating();
                ropes_scales.Add(new Vector2(100, 10));
                ropes_rotate.Add(0);
                ropes_position.Add(new Vector2(365,125));
                ropes_animation.Add(new Animation(ContentLoader.LoadTexture("stage_elements/rope"), 2, 1, 10));
                ropes_animation[ropes_animation.Count - 1].Animating();
                ropes_scales.Add(new Vector2(100, 10));
                ropes_rotate.Add(0);
                ropes_position.Add(new Vector2(460, 125));
                ropes_animation.Add(new Animation(ContentLoader.LoadTexture("stage_elements/rope"), 2, 1, 10));
                ropes_animation[ropes_animation.Count - 1].Animating();
                ropes_scales.Add(new Vector2(140, 10));
                ropes_rotate.Add(0);
                ropes_position.Add(new Vector2(560, 125));
                ropes_animation.Add(new Animation(ContentLoader.LoadTexture("stage_elements/rope"), 2, 1, 10));
                ropes_animation[ropes_animation.Count - 1].Animating();
                ropes_scales.Add(new Vector2(60, 10));
                ropes_rotate.Add(-55);
                ropes_position.Add(new Vector2(345, 125));

                pulley_positions.Add(new Vector2(375,145));
                pulley_rotations.Add(0);

                //left
                ropes_animation.Add(new Animation(ContentLoader.LoadTexture("stage_elements/rope"), 2, 1, 10));
                ropes_animation[ropes_animation.Count - 1].Animating();
                ropes_scales.Add(new Vector2(100, 10));
                ropes_rotate.Add(0);
                ropes_position.Add(new Vector2(240, 125));
                ropes_animation.Add(new Animation(ContentLoader.LoadTexture("stage_elements/rope"), 2, 1, 10));
                ropes_animation[ropes_animation.Count - 1].Animating();
                ropes_scales.Add(new Vector2(100, 10));
                ropes_rotate.Add(0);
                ropes_position.Add(new Vector2(160, 125));
                ropes_animation.Add(new Animation(ContentLoader.LoadTexture("stage_elements/rope"), 2, 1, 10));
                ropes_animation[ropes_animation.Count - 1].Animating();
                ropes_scales.Add(new Vector2(145, 10));
                ropes_rotate.Add(0);
                ropes_position.Add(new Vector2(20, 125));
                ropes_animation.Add(new Animation(ContentLoader.LoadTexture("stage_elements/rope"), 2, 1, 10));
                ropes_animation[ropes_animation.Count - 1].Animating();
                ropes_scales.Add(new Vector2(60, 10));
                ropes_rotate.Add(-55);
                ropes_position.Add(new Vector2(365, 125));

                pulley_positions.Add(new Vector2(325, 145));
                pulley_rotations.Add(0);

                hand_lifitng_texture = ContentLoader.LoadTexture("stage_elements/hand_lifting");
                hand_lifting_position = new Vector2(455, 190);
                hand_lifting_ropes_animation.Add(new Animation(ContentLoader.LoadTexture("stage_elements/rope"), 2, 1, 10));
                hand_lifting_ropes_animation[hand_lifting_ropes_animation.Count - 1].Animating();
                hand_lifiting_ropes_position.Add(new Vector2(470, 200));
                hand_lifing_ropes_scale.Add(new Vector2(70, 10));
                hand_lifting_ropes_rotation.Add(-1);

                hand_lifting_ropes_animation.Add(new Animation(ContentLoader.LoadTexture("stage_elements/rope"), 2, 1, 10));
                hand_lifting_ropes_animation[hand_lifting_ropes_animation.Count - 1].Animating();
                hand_lifiting_ropes_position.Add(new Vector2(510, 140));
                hand_lifing_ropes_scale.Add(new Vector2(190, 10));
                hand_lifting_ropes_rotation.Add(0);

                pulley_positions.Add(new Vector2(520,165));
                pulley_rotations.Add(0);

                fire_torch_position.Add(new Vector2(80,135));
                fire_torch_position.Add(new Vector2(180, 135));
                fire_torch_position.Add(new Vector2(280, 135));
                fire_torch_position.Add(new Vector2(400, 135));
                fire_torch_position.Add(new Vector2(500, 135));
                fire_torch_position.Add(new Vector2(600, 135));

            }

        }

        public void UpdateStage()
        {
            mechanism.Update();

            CheckStageSolved();
            CheckIncorrectSolution();

            if (stage_solved == true)
            {
                DoorGoUp();
            }

            if (stage_incorrect_solved == true)
            {
                if (killer_type == "sand")
                {
                    UpdtadeKillersSand();
                }
                else if (killer_type == "box")
                {
                    UpdateKillersBox();
                }
            }

            fire_torch_animation.Animating();
        }

        bool pressure_lever_down = true;
        long prev_time; 
        private void DoorGoUp()
        {
            long time = Convert.ToInt64(DateTime.Now.ToString("0MMddyyHmmssfff"));

            if (killer_type == "box")
            {
                if (door_texture_current_height > 30 && Math.Abs(player_position.X-hand_lifting_position.X)<40)
                {
                      door_texture_current_height--;
                      pulley_rotations[2] -= 0.1f;
                      hand_lifitng_rotation += 0.1f;

                      if (time - prev_time > 900)
                      {
                          Game1.mySoundEffects.Play("door_open");
                          prev_time = time;
                      }

                       for (int i = 0; i < hand_lifting_ropes_animation.Count; i++)
                       {
                            hand_lifting_ropes_animation[i].Animating();
                       }
                 }
                    
                
            }
            else if(killer_type=="sand")
            {
            
                    bool lifting_door = false;

                    if (Math.Abs(player_position.X - hydrolic_lifter_position.X) < 60 && door_texture_current_height>30 && player_position.Y>400)
                        if (pressure_lever_down == true)
                        {
                            if (pressure_lever_position.Y > 418)
                            {
                                pressure_lever_position = new Vector2(pressure_lever_position.X, pressure_lever_position.Y - 3);
                            }
                            else
                            {
                                pressure_lever_down = false;
                                lifting_door = true;
                            }
                        }
                        else
                        {
                            if (pressure_lever_position.Y < 450)
                            {
                                pressure_lever_position = new Vector2(pressure_lever_position.X, pressure_lever_position.Y + 3);
                            }
                            else
                            {
                                pressure_lever_down = true;
                                lifting_door = true;
                            }
                        }

                        if (door_texture_current_height > 30 && lifting_door == true)
                        {
                            door_texture_current_height-=2;
                            lever_position = new Vector2(lever_position.X, lever_position.Y - 2);
                            if (time - prev_time > 600)
                            {
                                Game1.mySoundEffects.Play("door_open");
                                prev_time = time;
                            }

                        }
                    
                
            }
        }
        private void UpdtadeKillersSand()
        {
            sand_animation.Animating();

            if (tube_door_height < 10)
            {
                killers_position[0] = new Vector2(killers_position[0].X + 1, killers_position[0].Y);
                if (killers_position[0].X + 750 > player_position.X ||
                    killers_position[0].X > stage_door_position.X)
                {
                    Game1.mySoundEffects.Play("death");
                    stage_reset = true;
                }
            }
            else
            {
                tube_door_height--;

                for (int i = 0; i < ropes_animation.Count; i++)
                {
                    ropes_animation[i].Animating();
                }
                for (int i = 0; i < pulley_rotations.Count; i++)
                {
                    pulley_rotations[i] += 0.1f;
                }
            }
        }

        private void UpdateKillersBox()
        {
            stage_door_position = new Vector2(stage_door_position.X - 1, stage_door_position.Y);
            killers_position[0] = new Vector2(killers_position[0].X + 1, killers_position[0].Y);

            if (Math.Abs((stage_door_position.X) - (killers_position[0].X+KillerTexture.Width)) < 70)
            {
                Game1.mySoundEffects.Play("death");
                stage_reset = true;
                
            }
            for (int i = 0; i < ropes_animation.Count; i++)
            {
                ropes_animation[i].Animating();
            }
            for (int i = ropes_animation.Count-2; i >((ropes_animation.Count-1)/2); i--)
            {
                
                pulley_rotations[0] -= 0.1f;
                if (ropes_position[i].X + ropes_scales[i].X <= ropes_position[(ropes_animation.Count - 1) / 2].X)
                {
                    ropes_position[i] = new Vector2(ropes_position[i].X + 1, ropes_position[i].Y);

                }
                else
                {
                    ropes_scales[i] = new Vector2(ropes_scales[i].X - 1, ropes_scales[i].Y);
                    if (i == ropes_animation.Count - 2)
                    {
                        ropes_scales[i] = new Vector2(ropes_scales[i].X - 8, ropes_scales[i].Y);
                    }
                }
            }
            for (int i = 0; i <(ropes_animation.Count-1)/2; i++)
            {
                ropes_animation[i].Animating();
                pulley_rotations[1] += 0.1f;
                if ((ropes_position[i].X > killers_position[0].X) && ropes_position[i].X > ropes_position[(ropes_animation.Count-1)].X)
                {
                    ropes_position[i] = new Vector2(ropes_position[i].X - 1, ropes_position[i].Y);
                }
                else
                {
                    ropes_scales[i] = new Vector2(ropes_scales[i].X - 1, ropes_scales[i].Y);
                }
            }
        }

        private void CheckIncorrectSolution()
        {
            if (mechanism.Done == true && mechanism.Solved == false)
            {
                stage_incorrect_solved = true;
            }
        }

        private void CheckStageSolved()
        {
            if (mechanism.Done == true && mechanism.Solved == true)
            {
                stage_solved = true;
            }
        }

        public void DrawStage(SpriteBatch sprite_batch)
        {
            

            sprite_batch.Draw(stage_door_texture,
                                   new Rectangle((int)(stage_door_position.X), (int)(stage_door_position.Y), door_texture_current_width, door_texture_current_height),
                                   null,
                                   Color.White,
                                   stage_door_angle,
                                   new Vector2(0, 0),
                                   SpriteEffects.None,
                                   0.0f);

            for (int i = 0; i < fire_torch_position.Count; i++)
            {
                if (killer_type == "box" && killers_position[0].X+killer_texture.Width < fire_torch_position[i].X && stage_door_position.X > fire_torch_position[i].X+fire_torch_animation.SpriteWidth)
                {
                    fire_torch_animation.DrawAnimation(sprite_batch, fire_torch_position[i]);
                }
                else if(killer_type=="sand")
                {
                    fire_torch_animation.DrawAnimation(sprite_batch, fire_torch_position[i]);
                }
            }

            if ((killer_type == "box" && stage_solved == false) || (stage_solved==true && killer_type=="box"))
            {
                for (int i = 0; i < killers_position.Count; i++)
                {
                    sprite_batch.Draw(killer_texture, killers_position[i], Color.White);
                }
            }

            if (killer_type == "box")
            {
                for (int i = 0; i < ropes_animation.Count; i++)
                {
                    ropes_animation[i].DrawScalableAndRotatableAnimation(sprite_batch, ropes_position[i], ropes_rotate[i], ropes_scales[i], 1f);
                }

                for (int i = 0; i <2; i++)
                {
                    sprite_batch.Draw(pulley_texture,
                                   new Rectangle((int)(pulley_positions[i].X), (int)(pulley_positions[i].Y),pulley_texture.Width, pulley_texture.Height),
                                   null,
                                   Color.White,
                                   pulley_rotations[i],
                                   new Vector2(pulley_texture.Width / 2, pulley_texture.Height/2),
                                   SpriteEffects.None,
                                   0.0f);
                }
                if (stage_solved == true || mechanism.Done == false)
                {
                   
                    for (int i = 0; i < hand_lifting_ropes_animation.Count; i++)
                    {
                        hand_lifting_ropes_animation[i].DrawScalableAndRotatableAnimation(sprite_batch, hand_lifiting_ropes_position[i], hand_lifting_ropes_rotation[i], hand_lifing_ropes_scale[i], 1f);
                    }
                    sprite_batch.Draw(hand_lifitng_texture,
                                      new Rectangle((int)(hand_lifting_position.X), (int)(hand_lifting_position.Y), hand_lifitng_texture.Width, hand_lifitng_texture.Height),
                                      null,
                                      Color.White,
                                      hand_lifitng_rotation,
                                      new Vector2(hand_lifitng_texture.Width / 2, hand_lifitng_texture.Height / 2),
                                      SpriteEffects.None,
                                      0.0f);
                    sprite_batch.Draw(pulley_texture,
                                   new Rectangle((int)(pulley_positions[2].X), (int)(pulley_positions[2].Y), pulley_texture.Width, pulley_texture.Height),
                                   null,
                                   Color.White,
                                   pulley_rotations[2],
                                   new Vector2(pulley_texture.Width / 2, pulley_texture.Height / 2),
                                   SpriteEffects.None,
                                   0.0f);

                }

            }
            if (killer_type == "sand")
            {
                sprite_batch.Draw(hydrolic_lifter,hydrolic_lifter_position,Color.White);
                sprite_batch.Draw(pressure_lever_texture, pressure_lever_position, Color.White);
                sprite_batch.Draw(lever_texture, lever_position, Color.White);

                if (stage_incorrect_solved == false)
                {
                    tube_position_offset = 0;
                    for (int i = 0; i < 3; i++)
                    {
                        sprite_batch.Draw(tube_texture,
                                      new Rectangle((int)(tube_position.X), (int)(tube_position.Y + tube_position_offset), tube_texture.Width, tube_texture.Height),
                                      null,
                                      Color.White,
                                      tube_angle,
                                      new Vector2(0, 0),
                                      SpriteEffects.None,
                                      0.0f);
                        tube_position_offset += tube_texture.Height;
                    }
                    
                }
                sprite_batch.Draw(tube_door_texture,
                                        new Rectangle((int)(tube_door_position.X), (int)(tube_door_position.Y), tube_door_texture.Width, tube_door_height),
                                        null,
                                        Color.White,
                                        3.15f,
                                        new Vector2(0, 0),
                                        SpriteEffects.None,
                                        0.0f);

                for (int i = 0; i < ropes_animation.Count; i++)
                {
                    ropes_animation[i].DrawScalableAndRotatableAnimation(sprite_batch, ropes_position[i], ropes_rotate[i], ropes_scales[i], 1f);
                }

                for (int i = 0; i < pulley_positions.Count; i++)
                {
                    sprite_batch.Draw(pulley_texture,
                                   new Rectangle((int)(pulley_positions[i].X), (int)(pulley_positions[i].Y), pulley_texture.Width, pulley_texture.Height),
                                   null,
                                   Color.White,
                                   pulley_rotations[i],
                                   new Vector2(pulley_texture.Width / 2, pulley_texture.Height / 2),
                                   SpriteEffects.None,
                                   0.0f);
                }
            }
            mechanism.Draw();

           
        }

        public void DrawStageKillers(SpriteBatch sprite_batch)
        {
            if (stage_incorrect_solved == true)
            {
                if (killer_type == "sand")
                {
                    sand_animation.DrawAnimation(sprite_batch, killers_position[0]);
                    tube_position_offset = 0;
                    for (int i = 0; i < 3; i++)
                    {
                        sprite_batch.Draw(tube_texture,
                                      new Rectangle((int)(tube_position.X), (int)(tube_position.Y + tube_position_offset), tube_texture.Width, tube_texture.Height),
                                      null,
                                      Color.White,
                                      tube_angle,
                                      new Vector2(0, 0),
                                      SpriteEffects.None,
                                      0.0f);
                        tube_position_offset += tube_texture.Height;
                    }
                }
                else if (killer_type == "box")
                {
                    for (int i = 0; i < killers_position.Count; i++)
                    {
                        sprite_batch.Draw(killer_texture, killers_position[i], Color.White);
                    }
                }
            }
        }

        public Mechanism Mechanism
        {
            get
            {
                return mechanism;
            }
        }

        public int StageNumber
        {
            get
            {
                return stage_number;
            }
        }

        public Vector2 StageDoorPosition
        {
            get
            {
                return stage_door_position;
            }
        }
        public Texture2D StageDoorTexture
        {
            get
            {
                return stage_door_texture;
            }
        }
        public int DoorTextureCurrentHeight
        {
            get
            {
                return door_texture_current_height;
            }
        }
        public int DoorTextureCurrentWidth
        {
            get
            {
                return door_texture_current_width;
            }
        }
        public bool StageReset
        {
            get
            {
                return stage_reset;
            }
        }
        public bool StageIncorrectSolved
        {
            get
            {
                return stage_incorrect_solved;
            }
        }
        public string KillerType
        {
            get
            {
                return killer_type;
            }
        }
        public Texture2D KillerTexture
        {
            get
            {
                return killer_texture;
            }
        }
        public List<Vector2> KillerPosition
        {
            get
            {
                return killers_position;
            }
        }
        public Vector2 PlayerPosition
        {
            set
            {
                player_position = value;
            }
        }
    }
}
